package oceanwiki.controller;


import oceanwiki.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Controller
@ResponseBody
@RequestMapping("/alipay")
public class AlipayController {
    @Autowired
    AlipayService alipayService;
    /**
     * web端订单支付
     *
     * @param outTradeNo 订单编号（唯一）
     * @param totalAmount 订单价格
     * @param subject 商品名称
     * Post请求 接口路径和前端要保持一致
     */
    @PostMapping("/pay")
    public String webPagePay(String outTradeNo, String totalAmount, String
            subject) throws Exception{
        return alipayService.webPagePay(outTradeNo,totalAmount,subject);
    }
    /**
     * 支付异步回调
     * @param request
     * @return
     * notifyUrl
     * Post请求 接口路径和前端要保持一致
     */
    @PostMapping("/notifyUrl")
    public String notifyUrl(HttpServletRequest request) throws Exception{
        return alipayService.notifyUrl(request);
    }

/**
 * 支付同步步回调
 * @param request
 * @return
 * returnUrl
 * Get请求 接口路径和前端要保持一致
 */
    @GetMapping("/returnUrl")
    public Map<String, String[]> returnUrl(HttpServletRequest request){
        return alipayService.returnUrl(request);
    }
}
